/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package banco;

import java.sql.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Mailson Kahl email: mkahl.colorado@hotmail.com
 */
public class ConnectionBD {

    private Connection conexao;
    public Statement statement;
    public ResultSet resultset;
    public PreparedStatement prep;

    public void conecta() throws Exception {
        Class.forName("org.sqlite.JDBC");
        conexao = DriverManager.getConnection("jdbc:sqlite://127.0.0.1:8000/db.sqlite3");
        statement = conexao.createStatement();
    }

    public void exec(String sql) throws Exception {
        resultset = statement.executeQuery(sql);
    }

    public void desconecta() {
        boolean result = true;
        try {
            conexao.close();
            JOptionPane.showMessageDialog(null, "banco fechado");
        } catch (SQLException fecha) {
            JOptionPane.showMessageDialog(null, "Não foi possivel "
                    + "fechar o banco de dados: " + fecha);
            result = false;
        }
    }
}
